package com.ruoyi.inspection.controller;

import com.ruoyi.common.constant.GlobalConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.inspection.constant.InspectionConstant;
import com.ruoyi.inspection.domain.GovernCheckTask;
import com.ruoyi.inspection.service.GovernCheckTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 政府下发专项任务表(GovernCheckTask)表控制层
 *
 * @author makejava
 * @since 2024-06-18 10:47:57
 */
@Slf4j
@RestController
@Api("专项检查任务接口")
@RequestMapping("/check/governCheckTask")
public class GovernCheckTaskController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private GovernCheckTaskService governCheckTaskService;

    /**
     * 分页查询
     *
     * @param governCheckTask 筛选条件
     * @return 查询结果
     */
    @ApiOperation("专项检查任务字典")
    @GetMapping("/distinct/list")
    public TableDataInfo taskDict(GovernCheckTask governCheckTask) {
        governCheckTask.setGovernCompanyCode(GlobalConstants.COMPANY_CODE);
        String currentYear = DateUtils.parseDateToStr(DateUtils.YYYY, new Date());
        currentYear = currentYear + "-01-01 00:00:00";
        Date currentDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, currentYear);
        governCheckTask.setGovernTaskStartTime(currentDate);

        List<GovernCheckTask> governCheckTasks = governCheckTaskService.queryByCompanyAndDate(governCheckTask);
        return getDataTable(governCheckTasks);
    }

    @ApiOperation("专项检查任务列表")
    @GetMapping("/list")
    public TableDataInfo queryByPage(GovernCheckTask governCheckTask) {
        startPage();
        List<GovernCheckTask> governCheckTasks = governCheckTaskService.queryByPage(governCheckTask);
        return getDataTable(governCheckTasks);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Long id) {
        return AjaxResult.success(this.governCheckTaskService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param governCheckTask 实体
     * @return 新增结果
     */
    @PostMapping
    public AjaxResult add(GovernCheckTask governCheckTask) {
        return AjaxResult.success(this.governCheckTaskService.insert(governCheckTask));
    }

    /**
     * 编辑数据
     *
     * @param governCheckTask 实体
     * @return 编辑结果
     */
    @PutMapping
    public AjaxResult edit(GovernCheckTask governCheckTask) {
        return AjaxResult.success(this.governCheckTaskService.update(governCheckTask));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public AjaxResult deleteById(Long id) {
        return AjaxResult.success(this.governCheckTaskService.deleteById(id));
    }

}

